package cn.stronglink.asset.module.basicdata.datacenter.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import cn.stronglink.asset.model.DataCenter;
import cn.stronglink.asset.module.basicdata.datacenter.mapper.DataCenterMapper;
import cn.stronglink.suite.core.util.WebUtil;

@Service
@Transactional(rollbackFor=Exception.class) 
public class DataCenterService {

	@Autowired
	private DataCenterMapper dataCenterMapper;

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page<DataCenter> queryDataCenter(Page<DataCenter> page,Map<String, Object>  params) {
		page.setRecords(dataCenterMapper.queryDataCenter(page,params));
		return page;	
	}
	
	public void removeDataCenter(Long id){
		dataCenterMapper.removeDataCenter(id);	
	}	

	public void insertDataCenter(DataCenter dataCenter) {
		if (dataCenter.getId() == null) {
			dataCenter.setId(IdWorker.getId());
			dataCenter.setCreateTime(new Date());
			dataCenter.setCreateBy(WebUtil.getCurrentUser());
			dataCenterMapper.insertDataCenter(dataCenter);		
		}else{
			dataCenter.setUpdateBy(WebUtil.getCurrentUser());
			dataCenter.setUpdateTime(new Date());
			dataCenterMapper.updateDataCenter(dataCenter);
		}	
		
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<DataCenter> queryAll() {
		return dataCenterMapper.queryAll();
	}

	

	

}
